//采用juqery后重写 del 和foreverdel
function del(id) {
	var keyValue;
	if (id) {
		keyValue = id;
	} else {
		keyValue = getSelectCheckboxValues();
	}
	if (!keyValue) {
		alert('请选择删除项！');
		return false;
	}
	if (window.confirm('确实要删除选择项吗？')) {
		$.post(URL + "/delete/", "id=" + keyValue + '&ajax=1', function(data) {
			$.messager.show({
				title: '提示信息',
				msg: data.info,
				timeout: 2000,
				showType: 'slide'
			});
			window.location.reload();
		} //function
		, "json"); //post	
	}
}
//永久删除
function foreverdel(id) {
	var keyValue;
	if (id) {
		keyValue = id;
	} else {
		keyValue = getSelectCheckboxValues();
	}
	if (!keyValue) {
		alert('请选择删除项！');
		return false;
	}
	$.messager.confirm('确认窗口', '确实要永久删除选择项吗？', function(r) {
		if (r) {
			$.post(URL + "/foreverdelete/", "id=" + keyValue + '&ajax=1', function(data) {
				$.messager.show({
					title: '提示信息',
					msg: data.info,
					timeout: 2000,
					showType: 'slide'
				});
				window.location.reload();
			} //function
			, "json"); //post	
		}
	});
}
//永久删除自己添加的记录
function delSelf(id) {
	var keyValue;
	if (id) {
		keyValue = id;
	} else {
		keyValue = getSelectCheckboxValues();
	}
	if (!keyValue) {
		alert('请选择删除项！');
		return false;
	}
	$.messager.confirm('确认窗口', '确实要永久删除选择项吗？', function(r) {
		if (r) {
			$.post(URL + "/delSelf/", "id=" + keyValue + '&ajax=1', function(data) {
				$.messager.show({
					title: '提示信息',
					msg: data.info,
					timeout: 2000,
					showType: 'slide'
				});
				if (data.status == 1) {
					window.location.reload();
					//$('#tr'+id).remove();
				}
			} //function
			, "json"); //post	
		}
	});
}

function mouseover(e){

}
function mouseout(e){

}
function change(e){
	
}
function goUrl(x){       
     window.location.href=x;       
} 
function backUrl(){
     window.location.href=$('#backUrl').val();       
}       
function getLocalTime(nS) {   
		t = new Date(parseInt(nS) * 1000);
		return t.getFullYear()+'-'+(t.getMonth()+1)+'-'+t.getDate();
} 
function sortBy (field,sort){
	location.href = "?_order="+field+"&_sort="+sort;
}
function cache(){
	ThinkAjax.send(URL+'/cache','ajax=1');
}
function forbid(id){
	location.href = URL+"/forbid/id/"+id;
}
function recycle(id){
	var keyValue;
	if (id)
	{
		keyValue = id;
	}else {
		keyValue = getSelectCheckboxValue();
	}
	if (!keyValue)
	{
		alert('请选择要还原的项目！');
		return false;
	}
	location.href = URL+"/recycle/id/"+keyValue;
}
function resume(id){
	location.href = URL+"/resume/id/"+id;
}
function trace(id){
	location.href = URL+"/trace/id/"+id;
}
function output(){
	location.href = URL+"/output/";
}
function read(id){
	var keyValue;
	if (id)
	{
		keyValue = id;
	}else {
		keyValue = getSelectCheckboxValue();
	}
	if (!keyValue)
	{
		alert('请选择编辑项！');
		return false;
	}
	location.href =  URL+"/read/id/"+keyValue;
}

function edit(id) {
	var keyValue;
	if (id) {
		keyValue = id;
	} else {
		keyValue = getSelectCheckboxValue();
	}
	if (!keyValue) {
		alert('请选择编辑项！');
		return false;
	}
	location.href = URL + "/edit/id/" + keyValue;
}

function slidemessage(msg) {
	$.messager.show({
		title: '消息提示',
		msg: msg,
		showType: 'slide'
	});
}
//取得今天的日期，今天GetDateStr(0)，明天GetDateStr(1),后天GetDateStr(2)等 。。。。。
function GetDateStr(AddDayCount){
	var dd = new Date();
	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
	var y = dd.getFullYear();
	var m = dd.getMonth()+1;//获取当前月份的日期
	var d = dd.getDate();
	m 	  = doHandleMonth(m);
    d     = doHandleMonth(d);
	return y+"-"+m+"-"+d;
}
function doHandleMonth(month){
    if(month.toString().length == 1){
              month = "0" + month;
    }
    return month;
}
/**
js将时间戳转为时间
 */
function unix2date(format, timestamp) {
	var a, jsdate = (timestamp) ? new Date(timestamp * 1000) : new Date();
	var pad = function(n, c) {
		if ((n = n + '').length < c) {
			return new Array(++c - n.length).join('0') + n;
		} else {
			return n;
		}
	}
	var f = {
		d: function() {
			return pad(f.j(), 2);
		},
		j: function() {
			return jsdate.getDate();
		},
		m: function() {
			return pad(f.n(), 2);
		},
		n: function() {
			return jsdate.getMonth() + 1;
		},
		Y: function() {
			return jsdate.getFullYear();
		},
		H: function() {
			return pad(jsdate.getHours(), 2);
		},
		i: function() {
			return pad(jsdate.getMinutes(), 2);
		},
		s: function() {
			return pad(jsdate.getSeconds(), 2);
		}
	};
	return format.replace(/[\\]?([a-zA-Z])/g, function(t, s) {
		if (t != s) {
			ret = s;
		} else if (f[s]) {
			ret = f[s]();
		} else {
			ret = s;
		}
		return ret;
	});
}
//以下代码为项目专用函数，可能不适宜所有项目使用/////////////////////////////////////////////////////////////
//showDetails,showFancybox弹出显示框，主要用于index页面的详细信息显示，a为jquery选择器对象如a = $('#hideImage a');，t为标题，如'效果图片‘,aname为actionName
//使用方法
//<div class="hide" id="hideDiv"></div><div class="hide" id="hideImage"></div>
//在js中直接showDetails,会查找相应模型的数据库，读取出相应的字段信息，并将里面的图片写入hideImage块中，
function showDetails(i,ff,title){
	//i为要读取的ID,f为要读取的字段，t为显示的标题
	f = ff?ff:"remarks";
	t = title?title:"备注";
	$.post(URL+'/myGetField/',{id:i,f:f},function(d){
		$('#hideDiv').html(d.data);
		if($('#hideDiv img').length>0){
			img = $('#hideDiv img').detach();//将返回数据的图片取出放入hideImage中
			$('#hideImage').html(img);
			$('#hideImage img').each(function(i){
				src	= this.src;	
				title	= this.alt+"<br>"+$('#hideDiv').html();	//标题由a标签的alt和html()里面的
				if(!$(this).parent().is('a')){
					$(this).wrap("<a href='"+ src +"' class='iGallay' rel='pmt' title='"+ title +"'></a>");
				}
			})//each
			a = $('#hideImage a');
		}else{
			$('#hideDiv').html($('#hideDiv').html()).width(555);
			a = $('#hideDiv');
		}
		//alert($('#hideDiv').html());
		showFancybox(a,t);
	},'json')
}
function showFancybox(a,t){
	if(a.size()>0){
		$.fancybox( a ,{fitToView:true,openEffect:'fade',loop:false,autoScale:true,minWidth:610,
			helpers:{title:{type:'inside' }},
			afterLoad : function() {
				this.title = '['+t+' ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' ] ' + this.title : ']');
			}//function
		});	//fancybox
	}else{
		$.messager.show({title:'提示信息',msg:'没有查询到有相关信息！',timeout:2000,showType:'slide'});	
	}
} 
//显示编辑器，n控件名，w宽度，h高度，将div_n的html()内容自动加载为编辑器内容
function showEditor(n,w,h){
	var ww = w>0?w:880;
	var hh = h>0?h:500;
	jQuery('#div_'+n).html("<TEXTAREA class=''  name='"+n+"' id='"+n+"'>"+$('#div_'+n).html()+"</textarea>");
	edt = KindEditor.create('textarea[name='+ n +']', {
		width:'100%',height:hh+'',allowFileManager:true,
		items : [
			'source','fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'emoticons', 'image', 'link','flash','media','insertfile','map']
	});	
	return edt;
}

